#ifndef STATE_H
#define STATE_H

#include "OgreSK.h"

class State;

class StateListener
{
public:
	StateListener(void) {};
	~StateListener(void) {};

	virtual void createState(Ogre::String stateName, State *state) = 0;
	virtual void changeState(State *state) = 0;
	virtual void popState(void) = 0;
	virtual void shutdown(void) = 0;
	virtual State* findByName(Ogre::String stateName) = 0;
};

class State : public OIS::KeyListener, public OIS::MouseListener, public OgreBites::SdkTrayListener
{
public:
	static void create(Ogre::String name, StateListener *mgr);

	void destroy() { delete this; }

	virtual void update(double timeSinceLastFrame) = 0;
	virtual void enter(void) = 0;
	virtual void exit(void) = 0;

protected:
	State(void) {};

	State* findByName(Ogre::String stateName) { return m_pManager->findByName(stateName); }
	void shutdown(void) { m_pManager->shutdown(); }
	void popState(void) { m_pManager->popState(); }

	StateListener		*m_pManager;

	Ogre::Camera		*m_pCamera;
	Ogre::SceneManager	*m_pSceneMgr;
	Ogre::FrameEvent	m_FrameEvent;
};

#define DECLARE_APPSTATE_CLASS(T)							\
static void create(Ogre::String name, StateListener *mgr)	\
{															\
	T *newState = new T();									\
	newState->m_pManager = mgr;								\
	mgr->createState(name, newState);						\
}															\

#endif